#!/usr/bin/python
#
# Process 'prepopulate.txt'
#

from pottononline.map.models import Marker,MarkerType
from django.contrib.auth.models import User
import os

print os.path.split(__file__)[0]

file = open(os.path.split(__file__)[0]+'/prepopulate.txt', "r")

for each in file:
  print each
  if len(each) > 1:
      if each[0] != '#':
        var_list = each.strip().split(',')
        if len(var_list) == 7:
          name,lat,lng,atype,phone,descr,link = var_list
          marker = Marker()
          marker.name = name.strip()
          marker.lat = lat.strip()
          marker.lon = lng.strip()
          mtype = MarkerType.objects.get(name=atype.strip())
          print type(mtype)
          marker.itemtype = mtype
          user = User.objects.get(pk=1)
          marker.owner_user = user;
          if len(phone) > 3:
            marker.public_phone = phone.strip()
          if len(descr) > 3:
            marker.description = unicode(descr,'utf-8', 'ignore' ).strip()
          if len(link) > 3:
            marker.link = link.strip()
          
          marker.save()
  
file.close()

